package Testdemo2;

import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:周次煜
 * Date: 2024-04-29
 * Time：0:01
 */



public class Test4 {
    public static int minSubArrayLen(int target, int[] nums) {
        int sz=nums.length;
        int left=0,right=1;
        int sum=nums[0];
        int [] len = new int[sz];
        int i=0;
        while(left < sz-1) {

            while(right < sz) {




                if (sum >= target) break;
                else {
                    sum += nums[right];

                    right++;
                }
            }



            if (sum >= target) {
                len[i]=right-left;
                i++;
            }

            sum -= nums[left];

            left++;

        }

        int min=len[0];
        for (int j = 1; j < i; j++) {
            if (min > len[j]) {
                min=len[j];
            }
        }

        return min;
    }


    public static void main(String[] args) {

        int[] array= {2,3,1,2,4,3};

        System.out.println(minSubArrayLen(7, array));

//        System.out.println(Integer.MAX_VALUE);




        Set<Character> set= new HashSet<>();
        set.add('1');
        set.add('2');
        set.add('3');
        set.add('4');
        System.out.println(set);
        set.clear();
        System.out.println(set);
    }
}


